<template>
  <div class="app-container">
    <div class="listBox">
      <div class="listBox_head">
        <el-button type="primary" style="margin: 10px 0 20px" @click="addView">新增权益券码</el-button>
      </div>
      <el-table v-loading="loading" :data="equityCardList" stripe border>
        <el-table-column label="序号" align="center" type="index" width="64px" />
        <el-table-column label="权益名称" align="center" prop="name" :show-overflow-tooltip="true" />
        <!-- <el-table-column label="权益类型" align="center" prop="type" :show-overflow-tooltip="true" /> -->
        <el-table-column label="权益类型" align="center" prop="type" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <dict-tag :options="equityInventoryTypeLs" :value="scope.row.type" />
          </template>
        </el-table-column>
        <el-table-column label="券码总数" align="center" prop="total" :show-overflow-tooltip="true" />
        <el-table-column label="可用数量" align="center" prop="usableNum" :show-overflow-tooltip="true" />
        <el-table-column label="未激活数量" align="center" prop="notActive" :show-overflow-tooltip="true" />
        <el-table-column label="已激活数量" align="center" prop="activeNum" :show-overflow-tooltip="true" />
        <el-table-column label="核销数量" align="center" prop="verificationNum" :show-overflow-tooltip="true" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="editClick(scope.row)">编辑</el-button>
            <el-button size="mini" type="text" @click="addCouponCode(scope.row)">添加券码</el-button>
            <el-button size="mini" type="text" @click="couponCodeDetail(scope.row)">券码明细</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList"></pagination>
    </div>
    <Dialog ref="dialog" @refresh="getList"></Dialog>
    <DialogAddCouponCode ref="dialogAddCouponCode" @refresh="getList"></DialogAddCouponCode>
    <DialogCouponCodeDetail ref="dialogCouponCodeDetail"></DialogCouponCodeDetail>
  </div>
</template>

<script>
  import {
    inventoryList,
    adminDict
  } from "@/api/equityManager/equityInventory";
  import Dialog from "@/views/equityManager/equityInventory/dialog";
  import DialogAddCouponCode from "@/views/equityManager/equityInventory/dialogAddCouponCode";
  import DialogCouponCodeDetail from "@/views/equityManager/equityInventory/dialogCouponCodeDetail";
  export default {
    // dicts: ['equity_card_status', ],
    name: "",
    components: {
      Dialog,
      DialogAddCouponCode,
      DialogCouponCodeDetail
    },
    data() {
      return {
        //日期
        date: [],
        //钱包地址弹窗
        dialogVisible: false,
        // 遮罩层
        loading: false,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 表格数据
        equityCardList: [],
        equityInventoryTypeLs: [], //权益类型数组
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
        }
      };
    },
    created() {
      this.getadminDict();
      this.getList();
    },
    methods: {
      getadminDict() {
        //获取权益类型字典
        const params = {
          dictType: "equity_inventory_type",
        };
        adminDict(params).then((res) => {
          this.equityInventoryTypeLs = res.result[0].dictList;
        });
      },
      /** 查询权益库存列表 */
      getList() {
        this.loading = true;
        inventoryList(this.queryParams).then(response => {
          this.equityCardList = response.result.records;
          this.equityCardList.forEach((item) => {
            item.notActive = Number(item.total) - Number(item.activeNum)
          })
          this.total = response.result.total;
          this.loading = false;
        });
      },
      // 表单重置
      reset() {
        this.date = []
        this.queryParams = {
          pageNum: 1,
          pageSize: 10,
        };
        // this.resetForm("form");
        this.handleQuery()
      },
      /** 新增 */
      addView() {
        this.$refs.dialog.open(null);
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.queryParams.chainTimeStart = this.date[0];
        this.queryParams.chainTimeEnd = this.date[1];
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        // this.resetForm("queryForm");
        this.reset();
        this.handleQuery();
      },
      /** 添加券码按钮操作 */
      addCouponCode(row) {
        this.$refs.dialogAddCouponCode.open(row);
      },
      /** 券码明细按钮操作 */
      couponCodeDetail(row) {
        this.$refs.dialogCouponCodeDetail.open(row);
      },
      /** 编辑按钮操作 */
      editClick(row) {
        this.$refs.dialog.open(row.id);
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$modal.confirm('是否确认导出所有数字权益卡列表数据项？').then(() => {
          this.exportLoading = true;
          return exportEquityCard(queryParams);
        }).then(response => {
          this.$download.name(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
      }
    }
  };

</script>
<style scoped>
  .head {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    padding: 20px 20px 0;
  }

  .listBox {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    padding: 20px 20px;
    margin-top: 10px;
  }

  .listBox_head {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

</style>
